package com.cjh.weixin.controller;

import com.cjh.common.response.Result;
import com.cjh.common.service.StoreOrderService;
import com.cjh.common.service.UploadService;
import com.cjh.common.wxDto.ApplyForRefundDTO;
import com.cjh.common.wxDto.WXStoreOrderDto;
import com.cjh.weixin.common.handler.UserThreadLocal;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cjh
 * @since 2022-01-26
 */
@RestController
@RequestMapping("/order")
public class StoreOrderController {
    @Autowired
    UploadService uploadService;
    @Autowired
    StoreOrderService storeOrderService;
    @PostMapping("/upload")
    public Result upload(@RequestBody MultipartFile file){
        String s = uploadService.uploadFile(file, "order-file/"+new SimpleDateFormat("yyyy/MM/dd").format(new Date())+"/");
        return new Result().setCode(0).setMessage("操作成功！").setData(s);
    }

    @PostMapping("/addOrder")
    public Result addOrder(@RequestBody WXStoreOrderDto wxStoreOrderDto){
        return storeOrderService.addOrder(wxStoreOrderDto, UserThreadLocal.get().getId());
    }

    @GetMapping("/getAllOrder")
    public Result getAllOrder(@RequestParam Integer current,@RequestParam Integer isNowDay){
        return storeOrderService.getAllOrder(current,isNowDay,UserThreadLocal.get().getId());
    }

    @GetMapping("/updateOrderStautsByOrderId")
    public Result updateOrderStautsByOrderId(@RequestParam Integer orderId,@RequestParam Integer status){
        return storeOrderService.updateOrderStautsByOrderId1(orderId,status);
    }

    @PostMapping("/applyForRefund")
    public Result applyForRefund(@RequestBody ApplyForRefundDTO applyForRefundDTO){
        return storeOrderService.applyForRefund(applyForRefundDTO);
    }

    @GetMapping("/cancelApplicationForRefund")
    public Result cancelApplicationForRefund(@RequestParam Integer orderId){
        return storeOrderService.cancelApplicationForRefund(orderId);
    }

//    @GetMapping("/getOrderById")
//    public Result getOrderById(@RequestParam Integer orderId){
//        return storeOrderService.getOrderById(orderId);
//    }
}
